$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/extractinfo/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true , hidden: true},
			{ label: '用户id', name: 'userId', index: 'user_id', width: 80 }, 			
			{ label: '提现成功描述', name: 'extractinfoDescribe', index: 'extractInfo_describe', width: 80 },
			{ label: '提现金额', name: 'extractinfoMoney', index: 'extractInfo_money', width: 80 }, 			
			{ label: '订单状态', name: 'status', index: 'status', width: 80 ,formatter: function(value, options, row){
                    if(value === 0){
                        return '<span class="label label-primary">申请提现</span>';
                    }
                    if(value === 1){
                        return '<span class="label label-primary">待打款</span>';
                    }
                    if(value === 2){
                        return '<span class="label label-success">提现成功</span>';
                    }
                    if(value === 3){
                        return '<span class="label label-success">申请失败</span>';
                    }
                }},
			{ label: '更新时间', name: 'updateTime', index: 'update_time', width: 80 }, 			
			{ label: '创建时间', name: 'createTime', index: 'create_time', width: 80 }, 			
			{ label: '用户类型', name: 'userType', index: 'user_type', width: 80 ,formatter: function(value, options, row){
                    if(value === 1){
                        return '<span class="label label-primary">用户</span>';
                    }
                    if(value === 2){
                        return '<span class="label label-success">技师</span>';
                    }
                    if(value === 3){
                        return '<span class="label label-success">店铺</span>';
                    }
                }}
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
        q:{
            userId : null
        },
		commissionExtractinfo: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.commissionExtractinfo = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "提现审核";
            console.log(id.id)
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
            // 订单状态 0 申请提现 1 待打款 2 提现成功 3 申请失败
            var url = "sys/extractinfo/update?id="+ vm.commissionExtractinfo.id +"&status="+1;
            if(event == 3){
                url = "sys/extractinfo/update?id="+ vm.commissionExtractinfo.id +"&status="+3;
            }
			$.ajax({
				type: "POST",
			    url: baseURL + url,
			    contentType: "application/json",
			    // data: JSON.stringify(vm.commissionExtractinfo),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "sys/extractinfo/delete",
				    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get(baseURL + "sys/extractinfo/info/"+id, function(r){
                vm.commissionExtractinfo = r.commissionExtractinfo;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
                postData:{
                    'userId': vm.q.userId
                },
                page:page
            }).trigger("reloadGrid");
		}
	}
});